package com.es.servlet; /**
 * 描述:
 * es-jsp-
 *
 * @author Derek
 * 创建时间：2022-04-25 10:00
 */

import com.es.bean.Student;
import com.es.service.StudentService;
import com.es.service.impl.StudentServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/reg")
public class RegServlet extends HttpServlet {
    StudentService service = new StudentServiceImpl();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //
        String name = request.getParameter("name");
        String address = request.getParameter("address");
        int age = Integer.parseInt(request.getParameter("age"));
        String telephone = request.getParameter("telephone");
        String sex = request.getParameter("sex");
        //把收集的数据放入到 数据库中？
        Student student = new Student();
        student.setName(name);
        student.setAddress(address);
        student.setAge(age);
        student.setTelephone(telephone);
        student.setSex(sex);
        //
        boolean flag = service.save(student);
        //
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        if(flag){
            out.println("保存成功");
        }else{
            out.println("保存失败");
        }

    }
}
